package com.mmz.security.browser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ViewResolver;

@Component
public class MyUserDetailsService implements UserDetailsService{
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private ViewResolver viewResolver;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        System.out.println(viewResolver);
        logger.info("登录用户名为: " + s);
        // 根据用户名查找用户信息
        String pw = passwordEncoder.encode("123456");
        logger.info(pw);
        return new User(s,pw, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
